﻿namespace HuwmanCode

open System
open HuwmanCode
open NUnit.Framework
open FsUnit

[<TestFixture>]
type ``String ``() =
    [<Test>]
    member this.``String.take - empty string returns empty string``() =
        String.Empty |> String.take(1) |> should equal String.Empty
    
    [<Test>]
    member this.``String.take - take too many returns no error``() =
        "1" |> String.take(2) |> should equal "1"

    [<Test>]
    member this.``String.take - take -1 returns empty string``() =
        "1" |> String.take(-1) |> should equal String.Empty

    [<Test>]
    member this.``String.take - take 1 returns correct result``() =
        "12" |> String.take(1) |> should equal "1"

    [<Test>]
    member this.``String.takeFromEnd - empty string returns empty string``() =
        String.Empty |> String.takeFromEnd(1) |> should equal String.Empty
    
    [<Test>]
    member this.``String.takeFromEnd - takeFromEnd too many returns no error``() =
        "1" |> String.takeFromEnd(2) |> should equal "1"

    [<Test>]
    member this.``String.takeFromEnd - takeFromEnd -1 returns empty string``() =
        "1" |> String.takeFromEnd(-1) |> should equal String.Empty

    [<Test>]
    member this.``String.takeFromEnd - takeFromEnd 1 returns correct result``() =
        "12" |> String.takeFromEnd(1) |> should equal "2"

    [<Test>]
    member this.``String.skip - empty string returns empty string``() =
        String.Empty |> String.skip(1) |> should equal String.Empty
    
    [<Test>]
    member this.``String.skip - skip too many returns empty string``() =
        "1" |> String.skip(2) |> should equal String.Empty

    [<Test>]
    member this.``String.skip - skip -1 returns full string``() =
        "1" |> String.skip(-1) |> should equal "1"

    [<Test>]
    member this.``String.skip - skip 1 returns correct result``() =
        "12" |> String.skip(1) |> should equal "2"

    [<Test>]
    member this.``String.skipFromEnd - empty string returns empty string``() =
        String.Empty |> String.skipFromEnd(1) |> should equal String.Empty
    
    [<Test>]
    member this.``String.skipFromEnd - skipFromEnd too many returns empty string``() =
        "1" |> String.skipFromEnd(2) |> should equal String.Empty

    [<Test>]
    member this.``String.skipFromEnd - skipFromEnd -1 returns full string``() =
        "1" |> String.skipFromEnd(-1) |> should equal "1"

    [<Test>]
    member this.``String.skipFromEnd - skipFromEnd 1 returns correct result``() =
        "12" |> String.skipFromEnd(1) |> should equal "1"

    [<Test>]
    member this.``String Active Pattern - Null string matched``() =
        let (s:string) = null

        let matched = 
            match s with 
            | Null -> true
            | _ -> false

        matched |> should be True

    [<Test>]
    member this.``String Active Pattern - Empty string matched``() =
        let (s:string) = ""

        let matched = 
            match s with 
            | Empty -> true
            | _ -> false

        matched |> should be True

    [<Test>]
    member this.``String Active Pattern - Whitespace string matched``() =
        let (s:string) = "   "

        let matched = 
            match s with 
            | Whitespace -> true
            | _ -> false

        matched |> should be True

    [<Test>]
    member this.``String Active Pattern - Text string matched``() =
        let (s:string) = "Hello"

        let matched = 
            match s with 
            | Text _ -> true
            | _ -> false

        matched |> should be True